<?php
class Default_Model_DbTable_Menu extends Zend_Db_Table_Abstract {
	protected $_name = 'menu';
	public function addMenu($parent_id, $menu_icon, $menu_name, $description, $status) {
		$data = array (
				'PARENT_ID' => $parent_id,
				'MENU_ICON' => $menu_icon,
				'MENU_NAME' => $menu_name,
				'DESCRIPTION' => $description,
				'STATUS' => $status 
		);
		return $this->insert ( $data );
	}
	public function updateMenu($id, $parent_id, $menu_icon, $menu_name, $description, $status) {
		$data = array (
				'PARENT_ID' => $parent_id,
				'MENU_ICON' => $menu_icon,
				'MENU_NAME' => $menu_name,
				'DESCRIPTION' => $description,
				'STATUS' => $status 
		);
		return $this->update ( $data, "ID = $id" );
	}
	public function updateStatus($id, $status) {
		$data = array (
				'STATUS' => $status 
		);
		return $this->update ( $data, "ID = $id" );
	}
	public function removeMenu($id) {
		return $this->delete ( "ID = $id" );
	}
	public function activeMenu($id) {
		$lv = $this->fetchRow ( "ID = $id" );
		if ($lv ["STATUS"] == 1) {
			$this->update ( array (
					"STATUS" => 0 
			), "ID = $id" );
		} else {
			$this->update ( array (
					"STATUS" => 1 
			), "ID = $id" );
		}
	}
	public function getAllMenuNoParent() {
		return $this->fetchAll ( "PARENT_ID = 0 AND STATUS = 1" )->toArray ();
	}
	public function getAllMenuHaveParent($parent_id) {
		return $this->fetchAll ( "PARENT_ID = $parent_id AND STATUS = 1" )->toArray ();
	}
	public function getMenuById($id) {
		return $this->fetchRow ( "ID = $id" )->toArray ();
	}
	public function getMenuByName($menu_name) {
		return $this->fetchRow ( "MENU_NAME = $menu_name" )->toArray ();
	}
	public function getAllMenu() {
		return $this->fetchAll ()->toArray();
	}
}

